package service

import (
	"fmt"
	"log"
	"shen/gotask/pkg/gotask"
	"shen/gotask/rocketmq/config"
	"shen/gotask/rocketmq/driver/rocketmq"
	"shen/gotask/rocketmq/logs"
	"sync"
)

type Service struct {
	Config             config.Model
	DriverCloseChannel chan bool
	Logs               *logs.Logs
}

func (r *Service) Run(wg *sync.WaitGroup) {
	defer func() {
		if err := recover(); err != nil {
			r.Logs.Error("服务端运行出错了，错误信息", err)
		}
	}()
	defer wg.Done()
	defer close(r.DriverCloseChannel)
	gotask.SetAddress(gotask.GetAddress())
	if err := gotask.Register(new(rocketmq.Producer)); err != nil {
		log.Fatalln(err)
	}
	fmt.Println("正在启动消息队列服务...")
	if err := gotask.Run(); err != nil {
		log.Fatalln(err)
	}
}
